package logic

import (
	"context"
	"doc-manage/models/mysql"
	"gorm.io/gorm"

	"doc-manage/docrpc/docrpc"
	"doc-manage/docrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DocUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDocUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocUpdateLogic {
	return &DocUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 医生修改
func (l *DocUpdateLogic) DocUpdate(in *docrpc.DocUpdateRequest) (*docrpc.DocUpdateResponse, error) {
	// todo: add your logic here and delete this line

	doctor := mysql.Doctor{
		Model: gorm.Model{ID: uint(in.DoctorId)},
		Name:  in.Name,
		Asc:   in.Asc,
		Desc:  in.Desc,
	}

	err := doctor.DoctorUpdate(mysql.DB, in.DoctorId)
	if err != nil {
		return nil, err
	}

	return &docrpc.DocUpdateResponse{
		DoctorId: int64(doctor.ID),
	}, nil
}
